import uuid from "uuid/v4";
import OSS from "ali-oss";
import { asyncossupload } from '../plugins/api'

export const updateoss = async (files) => {
  const res = await asyncossupload();
  const client = new OSS({
    region: "oss-cn-qingdao",
    accessKeyId: res.accessKeyId,
    accessKeySecret: res.accessKeySecret,
    stsToken: res.securityToken,
    bucket: "cdn-hterobot"
  });
  const x = files[0].name.split(".");
  const name = x[x.length - 1];
  const url = `school/${uuid()}.${name}`;
  await client.put(url, files[0]);
  return `https://cdn.hterobot.com/${url}`;
}